<template>
	<view>
		<mescroll-body :sticky="true" down="0" :bottombar="false" @init="mescrollInit" :down="downOption"
			@down="downCallback" :up="upOption" @up="upCallback">
			<view class="list-item" :class="item.article_status < 0 ? 'bg-break' : (item.article_status > 10 ? 'bg-complate' : '')" v-for="(item, index) in dataList" :key="index" @click="toDetail(item._id)">
				<u-steps class="steps" v-if="item.article_status > 0" :list="numList" mode="number" active-color="orange" :current="statusNum(item.article_status)"></u-steps>
				<view class="list-row">
					<view class="list-row-label">申请时间</view>
					{{ item._add_time_str }}
				</view>
				<view class="list-row">
					<view class="list-row-label">当前环节</view>
					{{ statusText(item.article_status) }}
				</view>
				<view class="list-row list-block text-ellipsis">
					{{ item.content }}
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 下拉刷新和上拉加载的组件
		data() {
			return {
				role: 'admin',
				title: '我的调解',
				action: '',

				dataList: [],

				numList: [{
					name: '待受理'
				}, {
					name: '已受理'
				}, {
					name: '调解完成'
				}],

				queryForm1: {
					// 表单数据源
					formData: {
						article_status: [], // 状态
					},
					// 查询匹配规则
					columns: [{
						key: "article_status",
						mode: "[]",
					}],
					// 排序规则
					sortRule: [{
						name: "_add_time",
						type: "desc"
					}]
				},
				downOption: {
					auto: false, //是否在初始化后,自动执行上拉回调callback; 默认true					
				},
				upOption: {
					auto: true, //是否在初始化后,自动执行上拉回调callback; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量
					},
					noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
					textNoMore: '没有更多数据',
					empty: {
						tip: '~ 搜索无结果 ~', // 提示
						btnText: ''
					}
				},
			}
		},
		computed: {
			
		},
		onLoad(options) {
			this.initPage(options);
		},
		methods: {
			initPage(options = {}) {
				this.role = vk.getVuex("$user.userInfo.role[0]")
				this.title = options.title || this.title;
				this.action = options.action || this.action;

				// console.log('this.role', this.role, vk.getVuex("$user.userInfo"))

				uni.setNavigationBarTitle({
					title: this.title
				})
			},
			toDetail(_id) {
				let url = `/pages_case/case/detail?id=${_id}`;
				vk.navigateTo(url);
			},
			statusNum(status){
				if(status < 0) return 0;  // 终止，但是步骤条中没有此项
				else if(status == 2) return 0;
				else if(status == 3) return 1;
				else if(status == 11) return 2;
			},
			// 获取列表
			upCallback(page) {
				let status = [];
				if(this.action == 'audit') status = [2, 2];
				else if(this.action == 'working') status = [3, 3];
				else if(this.action == 'over') status = [11, 11];
				
				this.queryForm1.formData.article_status = status;
				vk.callFunction({
						url: this.$api.NewsList,
						loading: true,
						data: {
							...this.queryForm1,
							pagination: {
								pageIndex: page.num, //当前页码
								pageSize: page.size, //每页显示数量
							},
						},
					})
					.then(res => {
						// console.log('获取列表res', res)

						this.mescroll.endSuccess(res.rows.length);
						if (res.code == 0) {
							if (page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
							this.dataList = this.dataList.concat(res.rows); //追加新数据
						} else vk.toast('暂无搜索内容');
					}).catch((err) => {
						console.log('联网失败, 结束加载', err)
						this.mescroll.endErr();
						vk.toast('暂无搜索内容');
					})
			},
			statusText(status) {
				if (status == -2) return '调解终止'
				if (status == -1) return '审核驳回'
				if (status == 2) return '审核中'
				if (status == 3) return '受理中'
				if (status == 4) return '等待申报人签字'
				if (status == 5) return '等待分配调解员'
				if (status == 6) return '调查中'
				if (status == 7) return '等待调解'
				if (status == 10) return '调解签名'
				if (status == 11) return '调解完成'
				if (status == 20) return '已回访'
				return status
			},
			categoryText(category_names) {
				if (category_names.length == 2) return category_names[0] + '/' + category_names[1];
				else return ""
			},
		}
	}
</script>